﻿//using Microsoft.Extensions.DependencyInjection;
//using Microsoft.Extensions.DependencyInjection.Extensions;
//using Microsoft.Extensions.Hosting;
//using Microsoft.Extensions.Logging;
//using Microsoft.Extensions.Logging.EventLog;
//using System;

//namespace Xms.Abp;

//public static class WindowsDesktopLifetimeHostBuilderExtensions
//{
//    public static IHostBuilder UseWindowsDesktop<TMainWindow>(this IHostBuilder builder)
//        where TMainWindow : Window
//    {
//        return builder.UseWindowsDesktop<TMainWindow>(options =>
//        {
//        });
//    }
//    public static IHostBuilder UseWindowsDesktop<TMainWindow>(this IHostBuilder builder, Action<WindowsDesktopLifetimeOptions> configure)
//        where TMainWindow : Window
//    {
//        builder.UseContentRoot(AppContext.BaseDirectory)
//            .ConfigureLogging((hostingContext, logging) =>
//            {
//                EventLoggerFactoryExtensions.AddEventLog(logging);
//            })
//            .ConfigureServices((context, services) =>
//            {
//                services.AddSingleton<IHostLifetime, WindowsDesktopLifetime>();
//                    //services.AddSingleton<Application>();
//                    services.TryAddSingleton<Application>();
//                services.TryAddTransient<TMainWindow>();
//                services.Configure<WindowsDesktopLifetimeOptions>(options =>
//                {
//                    options.MainWindowType = typeof(TMainWindow);
//                    options.ApplicationType = typeof(Application);
//                    configure?.Invoke(options);
//                });
//                services.Configure<EventLogSettings>(settings =>
//                {
//                    if (string.IsNullOrEmpty(settings.SourceName))
//                    {
//                        settings.SourceName = context.HostingEnvironment.ApplicationName;
//                    }
//                });
//            });
//        return builder;
//    }
//    public static IHostBuilder UseWindowsDesktop(this IHostBuilder builder)
//    {
//        return builder.UseWindowsDesktop(options =>
//        {
//        });
//    }
//    public static IHostBuilder UseWindowsDesktop(this IHostBuilder builder, Action<WindowsDesktopLifetimeOptions> configure)
//    {
//        builder.UseContentRoot(AppContext.BaseDirectory)
//            .ConfigureLogging((hostingContext, logging) =>
//            {
//                EventLoggerFactoryExtensions.AddEventLog(logging);
//            })
//            .ConfigureServices((context, services) =>
//            {
//                services.AddSingleton<IHostLifetime, WindowsDesktopLifetime>();
//                    //services.AddSingleton<Application>();
//                    services.TryAddSingleton<Application>();
//                services.Configure<WindowsDesktopLifetimeOptions>(options =>
//                {
//                    options.ApplicationType = typeof(Application);
//                    configure?.Invoke(options);
//                });
//                services.Configure<EventLogSettings>(settings =>
//                {
//                    if (string.IsNullOrEmpty(settings.SourceName))
//                    {
//                        settings.SourceName = context.HostingEnvironment.ApplicationName;
//                    }
//                });
//            });
//        return builder;
//    }
//}
